﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Common.Servers
{
    public class AssetServers
    {
	    private readonly IRepository<asset_reflect> asset_reflectRepository;

        public AssetServers()
        {
            asset_reflectRepository = new DapperRepository<asset_reflect>();

        }

        public List<asset_reflect> GetData()
        {
            var datas = asset_reflectRepository.GetAllEnumerable();

					  			return datas.ToList();
        }

        public asset_reflect GetModelById(string id)
        {
            return asset_reflectRepository.GetById(id);
        }

		
        internal void Add(asset_reflect model)
        {
            asset_reflectRepository.Insert(model);
        }

        internal void Update(asset_reflect model)
        {
            asset_reflectRepository.Update(model);
        }

		internal void Del(string id)
        {
            asset_reflectRepository.DeleteByIds(id);
        }

				      
        internal List<SelectListItem> GetTYPE_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = asset_reflectRepository.SqlWithParamsDynamic("select TYPE_ID Value,TYPE_NAME Text from [dbo].[asset_type]");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetDEPT_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = asset_reflectRepository.SqlWithParamsDynamic("select DEPT_ID Value,DEPT_NAME Text from [dbo].[department]");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetCPTL_KIND()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = asset_reflectRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=122");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }


                   
        internal List<SelectListItem> GetPRCS_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = asset_reflectRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=121");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }

        internal List<SelectListItem> GetKEEP_TYPE()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = asset_reflectRepository.SqlWithParamsDynamic("select CODE_NO Value, concat(CODE_NO, '-----', CODE_NAME) Text  from[dbo].[sys_code] where PARENT_NO = 139");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }

        internal List<SelectListItem> DCR_PRCS_IDData()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = asset_reflectRepository.SqlWithParamsDynamic("select CODE_NO Value,concat(CODE_NO,'-----',CODE_NAME) Text  from [dbo].[sys_code] where PARENT_NO=132");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }
    }
}